<?
// ELIMINAR   $$$$$$$$$$$$$$$$$$$$$$$$$$$


session_start();
if (isset($_SESSION['msgAlert'])){
	$msgAlert = $_SESSION['msgAlert'];
	unset($_SESSION['msgAlert']);
}

$stockIngresoId      = $StockIngresoFrm->id;   
$tipo                = $StockIngresoFrm->tipo;
$poNro               = $StockIngresoFrm->poNro;
$almId               = $StockIngresoFrm->almId;
$proveedorId         = $StockIngresoFrm->proveedorId;
$proveedorNombre     = $StockIngresoFrm->proveedorNombre;
$contacto            = $StockIngresoFrm->contacto;
$guiaRemNro          = $StockIngresoFrm->guiaRemNro;
$facturaNro          = $StockIngresoFrm->facturaNro;
$moneda              = $StockIngresoFrm->moneda;
$fechaGuiaRem        = $StockIngresoFrm->fechaGuiaRem;
$fechaIngreso        = $StockIngresoFrm->fechaIngreso;
$fechaFactura        = $StockIngresoFrm->fechaFactura;    
$flete               = $StockIngresoFrm->flete;
$totalBruto          = $StockIngresoFrm->totalBruto;
$dcto                = $StockIngresoFrm->dcto;
$neto                = $StockIngresoFrm->neto;    
$obs                 = $StockIngresoFrm->obs;
$contacto            = $StockIngresoFrm->contacto;
$status              = $StockIngresoFrm->status;
$crea_usr            = $StockIngresoFrm->crea_usr;
$crea_fecha          = $StockIngresoFrm->crea_fecha;
$modif_usr           = $StockIngresoFrm->modif_usr;
$modif_fecha         = $StockIngresoFrm->modif_fecha; 
$a_almacenesIngreso  = $StockIngresoFrm->listaAlmacenes;
$a_moneda            = $StockIngresoFrm->listaMoneda;
$a_tipoIngreso       = $StockIngresoFrm->listaTipoIngreso;
$a_stockIngresoLineas= $StockIngresoFrm->detalleLineas;
$total               = $StockIngresoFrm->total;
$totDcto             = $StockIngresoFrm->totDcto;
$totImpuesto         = $StockIngresoFrm->totImpuesto;
$totNeto             = $StockIngresoFrm->totNeto;

$contextMenu[1]["link"]      = "?do=StockIngreso&accion=shwForm";
$contextMenu[1]["linkIcon"]  = "application_add.png";
$contextMenu[1]["linkTitle"] = "Nueva recepcion";

$contextMenu[2]["link"]      = "?do=StockIngreso&accion=listarIngreso";
$contextMenu[2]["linkIcon"]  = "application_view_list.png";
$contextMenu[2]["linkTitle"] = "Lista";

$contextMenu[3]["link"]      = "?do=StockIngreso&accion=eliminarIngreso&stockIngresoId=".$stockIngresoId;
$contextMenu[3]["linkIcon"]  = "page_white_delete.png";
$contextMenu[3]["linkTitle"] = "Eliminar recepcion";

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<link href="../css/jquery/jquery-ui-1.8.6/css/smoothness/jquery-ui-1.8.6.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/main.js"></script>
<script type="text/javascript" src="../js/jquery/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="../js/jquery/jquery-ui-1.8.6/js/jquery-ui-1.8.6.custom.min.js"></script>
<script type="text/javascript" src="../js/jquery/jquery.blockUI.js"></script>
<script src="../js/jquery/jquery.alerts.js" type="text/javascript"></script>
<link href="../css/jquery/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" /> 
<link href="../css/menu.css" rel="stylesheet" type="text/css" media="screen" /> 
<script src="../js/menu_acordeon.js" type="text/javascript"></script>

<script type="text/javascript"> 
$(document).ready(function(){
   <? if ($msgAlert){?>
        jAlert("<? echo $msgAlert?>", "Aviso");
   <? }?>
   $("#datepicker").datepicker();
});
</script>
<script type="text/javascript">
	function addDetalle(id){	
		div = document.getElementById('moduleSectionDetalleAdd');
		$.post("index.php?do=StockIngreso&accion=shwFormLinea&stockIngresoId=<? echo $stockIngresoId?>", {regId : id}, function(data){
		$("#moduleSectionDetalleAdd").html(data);
		});			
	}
</script>
<script>
    function openWindow(url){
		window.open(url,'Wpopup','toolbar=no,location=no left=10 hight=10,scrollbars=yes,width=600,height=190,location=no');	
	}
     
</script>

<style>
	#moduleSection {
		margin:10 auto;
		width:98%;
		border-width: 1px; 
		border-style: solid; 
		border-color: #D0E8E8;
        position:relative;
        overflow:auto;  
	}
	#moduleSectionDetalleAdd {
		margin:5 auto;
		//background:#FFF;
		z-index:2;
		top :240px;
		padding:5px 5px 5px;
		position:absolute;
	}
    #moduleSectionDetalleAddList {
        margin:5 auto;
        //background:#FFF;
        z-index:20;
        top :100px;
        padding:10px 10px 10px;
        position:relative;
        height:300px;
    }     
</style>
    

<body>

<div id="main">
    
    <? include("header.inc");?>
    <div id="zonaContenedor">

    <div id="module">
	<h3>:: Ingreso de Mercadería</h3>
    <div>
     <form action="index.php?do=StockIngreso&accion=registrarIngreso" method="post">
	<table width="100%">
		<tr>
		  <td id="keyLabel">Ingreso Nro</td>

		  <td>
			<? if ($stockIngresoId){echo $stockIngresoId;}else{ echo "Nuevo";}?>
			<INPUT TYPE="hidden" NAME="stockIngresoId" value="<? echo $stockIngresoId;?>">
		  </td>
		  <td id="label">Status</td>
		  <td><input name="datepicker4" type="text" disabled="disabled" id="datepicker4" value="<? echo $status?>" size="12" readonly="readonly"/></td>
	    </tr>
		<tr>
		  <td id="label">Tipo</td>
		  <td><select name="tipo" id="tipo">
                    <option>
                    <? for ($i=0; $i< count($a_tipoIngreso); $i++){?>
                            <option <? if ($a_tipoIngreso[$i]["id"]== $tipo){echo "SELECTED";}?> value="<? echo $a_tipoIngreso[$i]["id"]?>"><? echo $a_tipoIngreso[$i]["valor"]?>
                    <? }?>
	      </select></td>
		  <td id="label">Fecha Ingreso</td>
		  <td><input type="text" name="datepicker" id="datepicker" size="12" value="<? echo $fechaIngreso?>"/></td>
	    </tr> 
		<tr>
		  <td id="label">Orden de Compra</td>
		  <td><input name="poNro" type="text" size="15" value="<? echo $poNro?>"></td>
		  <td id="label">Guia Nro</td>
		  <td><input type="text" name="guiaRemNro" id="guiaRemNro" size="12" value="<? echo $guiaRemNro?>"/></td>
		  </tr>
		<tr>
		  <td id="label">Almacen</td>
		  <td>
				<select name="almId" id="almId">
                    <option>
                    <? for ($i=0; $i< count($a_almacenesIngreso); $i++){?>
                            <option <? if ($a_almacenesIngreso[$i]["id"]== $almId){echo "SELECTED";}?> value="<? echo $a_almacenesIngreso[$i]["id"]?>"><? echo $a_almacenesIngreso[$i]["id"]."-".$a_almacenesIngreso[$i]["nombre"]?>
                    <? }?>
                </select>
		  </td>
		  <td id="label">Fecha Guia</td>
		  <td><input type="text" name="fechaGuiaRem" id="fechaGuiaRem" size="12" value="<? echo $fechaGuiaRem?>"/></td>
	    </tr>                 
		<tr>
		  <td id="label">Proveedor</td>
		  <td><input name="proveedorId" type="text" id="proveedorId" value="<? echo $proveedorId?>" size="7"/>
		    <input name="proveedorNombre" type="text" id="proveedorNombre" value="<? echo $proveedorNombre?>" size="40" maxlength="40"/></td>
		  <td id="label">Factura Nro</td>
		  <td><input type="text" name="facturaNro" id="facturaNro" readonly="readonly" size="12" value="<? echo $facturaNro?>"/></td>
		  </tr>
		<tr>
		  <td id="label">Contacto</td>
		  <td><input name="contacto" type="text" id="contacto" size="40" maxlength="40" value="<? echo $contacto?>"/></td>
		  <td id="label">Fecha Factura</td>
		  <td><input type="text" name="fechaFactura" id="fechaFactura" size="12" value="<? echo $fechaFactura?>"/></td>
		  </tr>
		<tr>

		  <td id="label">Observaciones</td>
		  <td>
          	<textarea name="obs" cols="40" rows="2"><? echo $obs?></textarea>          </td>
		  <td id="label" valign="top">Moneda</td>
		  <td valign="top">
                <select name="moneda" id="moneda">
                    <option>
                    <? for ($i=0; $i< count($a_moneda); $i++){?>
                            <option <? if ($a_moneda[$i]["id"]== $moneda){echo "SELECTED";}?> value="<? echo $a_moneda[$i]["id"]?>"><? echo $a_moneda[$i]["valor"]?>
                    <? }?>
                </select>
            </td>
	    </tr>        
		<tr>
		  <td></td>
		  <td></td>
		  <td></td>
		  <td><input type="submit" value="Guardar" name="aceptar2"/></td>
	    </tr>
     </table>
     </form>
    </div>
    <div>
		<TABLE width=100%>
			<TR>
				<TD>
					<table cellspacing="1" cellpadding="4">
						<tr>
							<td id="tabFormula" bgcolor="#CCCCCC" onclick="showGrid('gridFormula')"><a>Detalle</a></td>
							<td id="tabFase" bgcolor="#EBEBEB" onclick="showGrid('gridFase')">Condiciones comerciales  </td>                
						</tr>
					</table>        					
				</TD>
				<TD align=right>
					<!--<A HREF="javascript:openWindow('index.php?do=StockIngreso&accion=shwFormLinea&stockIngresoId=<? echo $stockIngresoId?>')">Nuevo</A>-->
                                        <a href="#" onclick="javascript:addDetalle();">Agregar detalle</a>
				</TD>
			</TR>
		</TABLE>
     </div>     
     <div id="gridFormula">
     <table width="100%">
		<tr>

			<td colspan="4">
				<table width="100%" cellspacing="1">
					<tr bgcolor="#CCCCCC" >
						<td>Item</td>
						<td>Codigo</td>
						<td>Descripcion</td>
						<td>UM</td>
						<td>Cantidad</td>
						<td>Costo</td>
						<td>Subtotal</td>
                              <td></td>                                 
					</tr>

                    <? 
					if ($a_stockIngresoLineas){
						$count_stockIngresoLineas = count($a_stockIngresoLineas);
						for ($i=0; $i< $count_stockIngresoLineas; $i++){
                                   ?>
							<tr bgcolor="#FFFFFF">
								<td><? echo $i+1?></td>
								<td><? echo $a_stockIngresoLineas[$i]["articuloId"]?></td>
								<td><? echo $a_stockIngresoLineas[$i]["descripcion"]?></td>
								<td><? echo $a_stockIngresoLineas[$i]["unidadMedida"]?></td>
								<td><div align="right"><? echo $a_stockIngresoLineas[$i]["cantidad"]?></div></td>
								<td><div align="right"><? echo $a_stockIngresoLineas[$i]["costo"]?></div></td>
								<td><div align="right"><? echo number_format($a_stockIngresoLineas[$i]["subtotal"],2)?></div></td>
                                                                <td><a href="index.php?do=StockIngreso&accion=borrarIngresoLinea&stockIngresoId=<? echo $stockIngresoId;?>&lineaId=<? echo $a_stockIngresoLineas[$i]["lineaId"]?>">eliminar</a></td>
							</tr>
                    <?       
                              }
					}?>
					<tr bgcolor="#FFFFFF">
					  <td colspan="3" bgcolor="#FFFFFF"><div align="right"></div></td>
					  <td colspan="3" bgcolor="#CCCCCC"><div align="right">Total</div></td>
					  <td bgcolor="#CCCCCC"><div align="right"><? echo number_format($total,2)?></div></td>

				  </tr>
					<tr bgcolor="#FFFFFF">
					  <td colspan="3" bgcolor="#FFFFFF"><div align="right"></div></td>
					  <td colspan="3" bgcolor="#CCCCCC"><div align="right">Descuentos</div></td>
					  <td bgcolor="#CCCCCC"><div align="right"><? echo $totDcto?></div></td>
				  </tr>
					<tr bgcolor="#FFFFFF">
					  <td colspan="3" bgcolor="#FFFFFF"><div align="right"></div></td>

					  <td colspan="3" bgcolor="#CCCCCC"><div align="right">Impuestos</div></td>
					  <td bgcolor="#CCCCCC"><div align="right"><? echo $totImpuesto?></div></td>
				  </tr>
					<tr bgcolor="#FFFFFF">
					  <td colspan="3" bgcolor="#FFFFFF"><div align="right"></div></td>
					  <td colspan="3" bgcolor="#CCCCCC"><div align="right"><strong>Neto</strong></div></td>
					  <td bgcolor="#CCCCCC"><div align="right"><strong><? echo number_format($totNeto,2)?></strong></div></td>

				  </tr>																		
				</table>
			</td>
		</tr>
	</table>	
        <? if ($stockIngresoId && count($a_stockIngresoLineas) > 0 && $status != 'C'){?> 
                <table width="100%">
                    <tr>
                        <td align="right">
                            <form name="frmCerrar" action="index.php?do=StockIngreso&accion=cerrarIngreso" method="post">
                            <input type="hidden" name="stockIngresoId" value="<? echo $stockIngresoId;?>"/>    
                            <input type="button" value="Generar movimiento" name="aceptar2" onclick="document.frmCerrar.submit();"/>		
                            </form>
                        </td>				
                    </tr>	
                </table>
        <? }?> 
    <br>&nbsp;
    <div id="moduleSectionDetalleAdd"> </div>    
    </div>

     <div id="gridFase" style="top:237px">

	</div>


		
	</div>
    <div id="footer"></div>
    <div id="moduleSectionDetalleAddList"> </div>
</div> 




</body>
</html>
